﻿
using KouDai.Phone.Engine;
using KouDai.Phone.Helper;
using KouDai.Phone.Models;
using KouDai.Phone.Parsers;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace KouDai.Phone.Services
{
    public static class ServiceManager
    {
        /// <summary>
        /// 获取图片强
        /// </summary>
        /// <param name="domainName"></param>
        /// <param name="minTimeStamp"></param>
        /// <returns></returns>
        public static async Task<BackData> GetImageWall(string domainName, long minTimeStamp)
        {
            //senddata
            Dictionary<string, object> body = new Dictionary<string, object>();
            body.Add("domainName", domainName);
            body.Add("minTimeStamp", 0);
            if (minTimeStamp == 0)
            {
                body.Add("maxTimeStamp", long.MaxValue);
            }
            else
            {
                body.Add("maxTimeStamp", minTimeStamp);
            }
            body.Add("limit", Constants.ImageSize);
            SendData sendData = new SendData(Constants.ImageWall, SendMethod.POST, EncryptType.AES, Constants.HeaderParas, body);
            //parser
            HoneyParser honeyParser = new HoneyParser();
            //backdata
            List<HoneyEntity> honeyList = new List<HoneyEntity>();
            BackData backData = new BackData(honeyList);
            //cdata
            CommunicationData cdata = new CommunicationData();
            cdata.SendData = sendData;
            cdata.Parser = honeyParser;
            cdata.BackData = backData;

            Task serviceTask = new HttpContentEngine().RequestAsync(cdata);
            await serviceTask.ConfigureAwait(false);
            await serviceTask;

            return backData;
        }

        /// <summary>
        /// 获取搜索分类数据
        /// </summary>
        /// <param name="parentId">层级编号</param>
        /// <param name="succCallback">成功的回调</param>
        /// <param name="failCallback">失败的回到</param>
        /// <returns></returns>
        public static async Task<BackData> GetSearchCategory(string parentId)
        {
            //1.sendata
            Dictionary<string, object> body = new Dictionary<string, object>();
            body.Add("parent_id", parentId);
            SendData sendData = new SendData(Constants.SearchCategory, SendMethod.POST, EncryptType.AES, Constants.HeaderParas, body);
            //2.parser
            SearchCategoryParser searchCategoryParser = new SearchCategoryParser();
            //3.backdata
            BackData backData = new BackData(new List<SearchCategoryEntity>());
            //4.cdata
            CommunicationData cdata = new CommunicationData();
            cdata.SendData = sendData;
            cdata.BackData = backData;
            cdata.Parser = searchCategoryParser;
            //5.Engine
            Task serviceTask = new HttpContentEngine().RequestAsync(cdata);
            await serviceTask.ConfigureAwait(false);
            await serviceTask;
            //5.Goto Queue
            return backData;
        }

        /// <summary>
        /// 热门请求
        /// </summary>
        /// <param name="succCallback"></param>
        /// <param name="failCallback"></param>
        public static async Task<BackData> GetHotInfo()
        {
            //1.body
            Dictionary<string, object> body = new Dictionary<string, object>();
            //string paras = ParamHelper.BuildParas(parasColl);
            SendData sendData = new SendData(Constants.Hotv3, SendMethod.POST, EncryptType.AES, Constants.HeaderParas, body);
            //2.Parser
            CategoryParser categoryParser = new CategoryParser();
            //3.backdata
            BackData backData = new BackData(new List<HotEntity>());
            //4.cdata
            CommunicationData cdata = new CommunicationData();
            cdata.SendData = sendData;
            cdata.BackData = backData;
            cdata.Parser = categoryParser;
            //5.Engine
            Task serviceTask = new HttpContentEngine().RequestAsync(cdata);
            await serviceTask.ConfigureAwait(false);
            await serviceTask;
            //5.Goto Queue
            return backData;
        }

        public static async Task<BackData> GetMyStreet(long minTimeStamp, int flag = 1, int isFirst = 1, string algorithm = "12", int limit = Constants.ImageSize)
        {
            //1.body
            Dictionary<string, object> body = new Dictionary<string, object>();
            body.Add("minTimeStamp", 0);
            if (minTimeStamp == 0)
            {
                body.Add("maxTimeStamp", long.MaxValue);
            }
            else
            {
                body.Add("maxTimeStamp", minTimeStamp);
            }
            body.Add("limit", limit);
            SendData sendData = new SendData(Constants.GetMyStreetProducts, SendMethod.POST, EncryptType.AES, Constants.HeaderParas, body);
            //2.Parser
            CategoryParser categoryParser = new CategoryParser();
            //3.backdata
            BackData backData = new BackData(new List<HotEntity>());
            //4.cdata
            CommunicationData cdata = new CommunicationData();
            cdata.SendData = sendData;
            cdata.BackData = backData;
            cdata.Parser = categoryParser;
            //5.Engine
            await new HttpContentEngine().RequestAsync(cdata).ConfigureAwait(false);
            //5.Goto Queue
            return backData;
        }

        /// <summary>
        /// 获取v3排行榜
        /// </summary>
        public static async Task<BackData> GetRankingList(string startDate, string domainName)
        {
            //1.body
            Dictionary<string, object> body = new Dictionary<string, object>();
            body.Add("startDate", startDate);
            body.Add("domainName", domainName);
            SendData sendData = new SendData(Constants.HotList, SendMethod.POST, EncryptType.AES, Constants.HeaderParas, body);
            //2.Parser
            HotListParser hotListParser = new HotListParser();
            //3.backdata
            BackData backData = new BackData(new List<RankingListEntity>());
            //4.cdata
            CommunicationData cdata = new CommunicationData();
            cdata.SendData = sendData;
            cdata.BackData = backData;
            cdata.Parser = hotListParser;
            //5.Engine
            Task serviceTask = new HttpContentEngine().RequestAsync(cdata);
            await serviceTask.ConfigureAwait(false);
            await serviceTask;
            //5.Goto Queue
            return backData;
        }
    }
}
